package com.lyshop.guiyingshanding.adapters;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.core.content.ContextCompat;


import com.lyshop.guiyingshanding.R;
import com.lyshop.guiyingshanding.base.BaseRVAdapter;
import com.lyshop.guiyingshanding.base.BaseRVHolder;
import com.lyshop.guiyingshanding.base.BaseViewHolder;
import com.zc.mychart.model.GoodsItemBean;
import com.zc.mychart.utils.FormatUtil;

import java.util.List;

public class OrderTypeRVAdapter extends BaseRVAdapter<GoodsItemBean> {
    private LinearLayout ll_type_bg;
    private TextView tv_unit_price;
    private TextView tv_remark;
    private ImageView iv_vip;

    private int mType = 1;//1现价 2结算
    private int mPosition = 0;

    public OrderTypeRVAdapter(Context context, List<GoodsItemBean> list) {
        super(context, list);
    }

    @Override
    public int onCreateViewLayoutID(int viewType) {
        return R.layout.item_probean_type;
    }

    @Override
    public void onBindView(BaseRVHolder mHolder, int position) {
        BaseViewHolder holder = mHolder.getViewHolder();
        ll_type_bg = holder.get(R.id.ll_type_bg);
        tv_unit_price = holder.get(R.id.tv_unit_price);
        tv_remark = holder.get(R.id.tv_remark);
        iv_vip = holder.get(R.id.iv_vip);
    }

    @Override
    public void onBindViewHolder(BaseRVHolder holder, int position) {
        super.onBindViewHolder(holder, position);
        GoodsItemBean bean = mList.get(position);
        if (mPosition == position) {
            if (mType == 2) {
                ll_type_bg.setBackgroundResource(R.drawable.btn_red_default_shape);
            } else {
                ll_type_bg.setBackgroundResource(R.drawable.btn_green_default_shape);
            }
            tv_unit_price.setTextColor(ContextCompat.getColor(mContext,R.color.white));
            tv_remark.setTextColor(ContextCompat.getColor(mContext,R.color.white));
        } else {
            ll_type_bg.setBackgroundResource(R.drawable.border_gray_tab_dp6);
            tv_unit_price.setTextColor(ContextCompat.getColor(mContext,R.color.color_black_01));
            tv_remark.setTextColor(ContextCompat.getColor(mContext,R.color.color_black_02));
        }

        String remark = FormatUtil.formatDouble2(bean.weight) + bean.unit;
        tv_unit_price.setText(FormatUtil.formatDouble2(bean.unit_price) + "元");
        tv_remark.setText(remark);
        if (bean.isEnjoy == 1){
            iv_vip.setVisibility(View.VISIBLE);
        } else {
            iv_vip.setVisibility(View.GONE);
        }
    }

    public void setType(int type) {
        this.mType = type;
        notifyDataSetChanged();
    }

    public void setPosition(int position) {
        this.mPosition = position;
        notifyDataSetChanged();
    }
}
